<?php
$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

$conn = new mysqli($servername, $username, $password, $dbname);

if ($conn->connect_error) {
    die("连接失败: " . $conn->connect_error);
}
$conn->set_charset("utf8");

$data = file_get_contents("php://input");
$modifyinfo = json_decode($data, true);
$id = $modifyinfo['id'] ?? '';
$name = $modifyinfo['name'] ?? '';
$college = $modifyinfo['college'] ?? '';
$grade = $modifyinfo['grade'] ?? '';

$sql = "SELECT * FROM user WHERE id = '$id'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    $updateSql = "UPDATE user SET name = '$name', college = '$college', grade = '$grade' WHERE id = '$id'";
    
    if ($conn->query($updateSql) === TRUE) {
        echo "记录更新成功";
    } else {
        echo "Error: " . $conn->error;
    }
} else {
    echo "未找到对应记录";
}
$conn->close();
?>
